package chatRoom.com.fenwe.util;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.util.StringUtils;

public class CodeCreateUtil {
    private static String PARENTTHESES_PREFIX = "(";
    private static String PARENTTHESES_SUFFIX = ")";
    private static String BRACKET_PREFIX = "[";
    private static String BRACKET_SUFFIX = "]";
    private static String BLANK = " ";
    private static String COLON = ":";

    public static String createLogMessage(String methodName, String message) {
        StringBuffer stringBuffer = new StringBuffer(nowTimeFormat());
        stringBuffer.append(" 方法").append(BRACKET_PREFIX).append(methodName).append(BRACKET_SUFFIX).append("出现错误，")
                .append("错误信息：").append(message);
        return stringBuffer.toString();
    }

    private static String nowTimeFormat() {
        SimpleDateFormat format = new SimpleDateFormat("YYYY-MM-dd hh:mm:ss");
        return format.format(new Date());
    }

    public static String createRequireId(long projectId, String requireNumber) {

        return new StringBuffer(convertSystemNum(projectId)).append("03").append(requireNumber).toString();
    }

    public static String convertSystemNum(Long i) {

        String code = i + "";
        int leng = (code.trim()).length(); // 定义长度
        if (leng == 1) {
            code = "000" + i;
        } else if (leng == 2) {
            code = "00" + i;
        } else if (leng == 3) {
            code = "0" + i;
        } else if (leng == 4) {
            code = "" + i;
        }
        return code;
    }

    public static String createBaselineRemark(String oldVersion, String newVersion, boolean isBased) {
        StringBuffer sBuffer = new StringBuffer();
        if (isBased) {
            sBuffer.append("新建基线版本：" + newVersion + ",上一个基线已打基线，版本为：" + oldVersion);
        } else {
            sBuffer.append("新建基线版本：" + newVersion + ",上一个基线未打基线，版本为：" + oldVersion);
        }
        return sBuffer.toString();
    }

    public static String createRequireRemark(String parentId) {
        StringBuffer sBuffer = new StringBuffer();
        if (StringUtils.isEmpty(parentId)) {
            sBuffer.append("新建需求");
        } else {
            sBuffer.append("新建子需求");
        }
        return sBuffer.toString();
    }

    public static void main(String[] args) {
        StackTraceElement[] stacks = new Throwable().getStackTrace();
        System.out.println(Thread.currentThread().getStackTrace()[1].getClassName());
        System.out.println(Thread.currentThread().getStackTrace()[1].getMethodName());
    }
}
